            (function ($) {
var cancel = function() {
$(this).closest('.ui-dialog-content').dialog('close');
}
var cancelform = function(e) {
e.preventDefault();
$(this).closest('.ui-dialog-content').dialog('close');
}
var doupload = function() {
$(this).closest('.ui-dialog-content').dialog('close');
$('#upload').submit();
$('#uploadprogress').dialog(progressoptions);
}

var standardoptions = {
modal: true,
        buttons: {
            "Cancel Upload": cancel
        }
};

var progressoptions = {
modal: true,
        buttons: {
            "Cancel Upload": cancel
        }
};

var confirmoptions = {
modal: true,
        buttons: {
            "I accept": doupload,
            "I decline": cancel
        }
};

                // We'll use this to cache the progress bar node
                var pbar;
 
                // This flag determines if the upload has started
                var started = false;
 
                $(function () {

// Verify file extension

// Start progress tracking when the form is submitted
                    $('.button').click(function(e) {

$('#file').change(function() {
var ext = $('#file').val().split('.').pop().toLowerCase();
if($.inArray(ext, ['mp3','mp4','wav','wma']) == -1) {
e.preventDefault();
    $("#uploadextension").dialog(standardoptions);
}
});

$("#uploadconfirm").dialog(confirmoptions);

                        // We know the upload is complete when the frame loads
                        $('#uploadframe').load(function () {
 


                            // This is to prevent infinite loop
                            // in case the upload is too fast
                            started = true;
 
                            // Do whatever you want when upload is complete
//                            $(this).dialog("close");
$("#uploadresult").dialog(resultoptions);

 
                        });
 
                        // Start updating progress after a 1 second delay
                        setTimeout(function () {
 
                            // We pass the upload identifier to our function
                            updateProgress($('#key').val());
 
                        }, 1000);
 
                    });
 
                });
 
                function updateProgress(id) {
 
                    var time = new Date().getTime();
 
                    // Make a GET request to the server
                    // Pass our upload identifier as a parameter
                    // Also pass current time to prevent caching
                    $.get('http://audioshout.com/progress.php', { key: id, t: time }, function (data) {
 
                        // Get the output as an integer
                        var progress = parseInt(data, 10);
 
                        if (progress < 100 || !started) {
 
                            // Determine if upload has started
                            started = progress < 100;
 
                            // If we aren't done or started, update again
                            updateProgress(id);
 
                        }
 
                        // Update the progress bar percentage
                        // But only if we have started
//                        started && pbar.progressbar('value', progress);
 
                    });
 
                }

}(jQuery));
